// miniprogram/pages/detail/detail.js'
const db = wx.cloud.database();
const productsCollection = db.collection('products');
const limit = 20 ;


const size = [{
  "id": "1",
  "size": "35"
},
{
  "id": "2",
  "size": "36"
},
{
  "id": "3",
  "size": "37"
},
{
  "id": "4",
  "size": "38"
},
{
  "id": "5",
  "size": "39"
},
{
  "id": "6",
  "size": "40"
},
{
  "id": "7",
  "size": "42"
},
{
  "id": "8",
  "size": "43"
},
{
  "id": "9",
  "size": "44"
}
]
Page({

  /**
   * 页面的初始数据
   */
  data: {
    number: 1,
    activeColIndex: -1,
    activeSizeIndex: -1,
    productinfo:[],
    size,
    showShare: false,
    show: false,
    activeNames: [],
    options: [
      { name: '微信', icon: 'wechat', openType: 'share' },
      { name: '微博', icon: 'weibo' },
      { name: '复制链接', icon: 'link' },
      { name: '分享海报', icon: 'poster' },
      { name: '二维码', icon: 'qrcode' },
    ],
  },
  onClickButton(){
    console.log("立即购买")
  },
  addToShopcar(){
    console.log("加入购物车")
  },
  reduceNum() {
    if (this.data.number < 1) {
      wx.showToast({
        title: '不能在减少了',
      });
      this.data.number = 1
    }
    this.setData({
      number: --this.data.number
    })
  },
  increaseNum() {
    if (this.data.number > 5) {
      wx.showToast({
        title: '亲~不野性消费',
      })
    }
    this.setData({
      number: ++this.data.number
    })
  },
  changeColor(event) {
    // console.log(event);
    let { index } = event.currentTarget.dataset;
    this.setData({
      activeColIndex: index
    })
  },
  changeSize(e) {
    let { index } = e.currentTarget.dataset;
    this.setData({
      activeSizeIndex: index
    })
  },
  onChange(event) {
    this.setData({
      activeNames: event.detail,
    });
  },
  showPopup() {
    this.setData({ show: true });
  },

  onClick(event) {
    this.setData({ showShare: true });
  },

  onClose() {
    this.setData({ showShare: false, show: false });
  },

  onSelect(event) {
    Toast(event.detail.name);
    this.onClose();
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    // console.log(typeof options.id);
    const id = parseInt(options.id);
    // console.log(id);
    wx.setNavigationBarTitle({
      title: '商品详情',
    })
    let{total} = await productsCollection.count()
    this.setData({
      total:total,
      page:1,
    })
    let {data} = await productsCollection
    .where({
      id: db.command.eq(id)
    })
    .get();
  //  console.log(productinfo);
    this.setData({
      productinfo:data
    })
    console.log(this.data.productinfo[0].picarry[0]);
    
   
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})